package jjn.daily;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * @author Jjn
 * @since 2023/8/24 17:14
 */
public class LeetCode1267 {
    public int countServers(int[][] grid) {
        int m = grid.length;
        int n = grid[0].length;
        Map<Integer, Integer> rowMap = new HashMap<>();
        Map<Integer, Integer> columnMap = new HashMap<>();
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (grid[i][j] == 1) {
                    rowMap.put(i, rowMap.getOrDefault(i, 0) + 1);
                    columnMap.put(j, columnMap.getOrDefault(j, 0) + 1);
                }
            }
        }
        int total = 0;
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (grid[i][j] == 1 && (rowMap.get(i) > 1 || columnMap.get(j) > 1)) {
                    total++;
                }
            }
        }
        return total;
    }
    
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int m = scanner.nextInt();
        int n = scanner.nextInt();
        int[][] grid = new int[m][n];
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                grid[i][j] = scanner.nextInt();
            }
        }
        int countServers = new LeetCode1267().countServers(grid);
        System.out.println(countServers);
    }
}
